package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhUserBanner;
import com.ruoyi.zsyh.service.IZsyhUserBannerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户端轮播管理Controller
 * 
 * @author yuexl
 * @date 2022-02-21
 */
@Controller
@RequestMapping("/zsyh/userBanner")
public class ZsyhUserBannerController extends BaseController
{
    private String prefix = "zsyh/userBanner";

    @Autowired
    private IZsyhUserBannerService zsyhUserBannerService;

    @RequiresPermissions("zsyh:userBanner:view")
    @GetMapping()
    public String userBanner()
    {
        return prefix + "/userBanner";
    }

    /**
     * 查询用户端轮播管理列表
     */
    @RequiresPermissions("zsyh:userBanner:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhUserBanner zsyhUserBanner)
    {
        startPage();
        List<ZsyhUserBanner> list = zsyhUserBannerService.selectZsyhUserBannerList(zsyhUserBanner);
        return getDataTable(list);
    }

    /**
     * 导出用户端轮播管理列表
     */
    @RequiresPermissions("zsyh:userBanner:export")
    @Log(title = "用户端轮播管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhUserBanner zsyhUserBanner)
    {
        List<ZsyhUserBanner> list = zsyhUserBannerService.selectZsyhUserBannerList(zsyhUserBanner);
        ExcelUtil<ZsyhUserBanner> util = new ExcelUtil<ZsyhUserBanner>(ZsyhUserBanner.class);
        return util.exportExcel(list, "用户端轮播管理数据");
    }

    /**
     * 新增用户端轮播管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户端轮播管理
     */
    @RequiresPermissions("zsyh:userBanner:add")
    @Log(title = "用户端轮播管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhUserBanner zsyhUserBanner)
    {
        return toAjax(zsyhUserBannerService.insertZsyhUserBanner(zsyhUserBanner));
    }

    /**
     * 修改用户端轮播管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhUserBanner zsyhUserBanner = zsyhUserBannerService.selectZsyhUserBannerById(id);
        mmap.put("zsyhUserBanner", zsyhUserBanner);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户端轮播管理
     */
    @RequiresPermissions("zsyh:userBanner:edit")
    @Log(title = "用户端轮播管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhUserBanner zsyhUserBanner)
    {
        return toAjax(zsyhUserBannerService.updateZsyhUserBanner(zsyhUserBanner));
    }

    /**
     * 删除用户端轮播管理
     */
    @RequiresPermissions("zsyh:userBanner:remove")
    @Log(title = "用户端轮播管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhUserBannerService.deleteZsyhUserBannerByIds(ids));
    }
}
